#!/bin/sh

EBC_PORT=${EBC_PORT:-908}

function usage()
{
    cat <<EOF
Usage: ebcportctl [-adih]
options:
  -a: activate ebc port
  -d: deactivate ebc port
  -i <interface>: nic interface to be activated/deactivated
  -h: help

EOF
}

IPTABLES=${IPTABLES:-iptables}
IPTABLES_MODE=-A
INTERFACE=
INPUT_INTERFACE=
OUTPUT_INTERFACE=

while getopts adi:h c; do
    case $c in
	a)
	    IPTABLES_MODE=-D
	    ;;
	d)
	    IPTABLES_MODE=-A
	    ;;
	i)
	    INTERFACE=$OPTARG
	    ;;
	h)
	    usage
	    exit 0
	    ;;
	*)
	    usage
	    exit 1
	    ;;
    esac
done

if [ ! -z $INTERFACE ]; then
    INPUT_INTERFACE="-i $INTERFACE"
    OUTPUT_INTERFACE="-o $INTERFACE"
fi

iptables $IPTABLES_MODE INPUT -p tcp --dport $EBC_PORT $INPUT_INTERFACE -j DROP
iptables $IPTABLES_MODE OUTPUT -p tcp --dport $EBC_PORT $OUTPUT_INTERFACE -j DROP
iptables $IPTABLES_MODE INPUT -p udp --dport $EBC_PORT $INPUT_INTERFACE -j DROP
iptables $IPTABLES_MODE OUTPUT -p udp --dport $EBC_PORT $OUTPUT_INTERFACE -j DROP
